Saturday, June 25, 2016

Telling your computer what to do

Telling your computer what to do

Some programming languages you might have heard of:

  • R
  • Matlab
  • Python
  • JavaScript
  • html

Interacting with your computer

Interacting with your computer

Interacting with your computer

Creating variables

baby <- 'Meredith'
sculpture <- 10
baby 
## [1] "Meredith"
sculpture
## [1] 10

What types of information does your computer understand?

  • numeric
    • integers, e.g. 1, 2, 3
    • doubles, e.g. 1.25, 3.78
    • complex numbers, e.g. 3 + 2i
  • character or string
    • e.g. "Research", "Platforms"
  • logical or Boolean
    • e.g. TRUE and FALSE

How can we group information?

  • vectors / tuples
  • matrices / data.frames / arrays
  • lists / structures
  • dictionaries

vectors / tuples

vectors / tuples

vector1 <- 1:10
vector2 <- c("learning", "to", "code", "is", "fun")
vector1
##  [1]  1  2  3  4  5  6  7  8  9 10
vector2
## [1] "learning" "to"       "code"     "is"       "fun"

matrices / data.frames / arrays

matrices / data.frames / arrays

PlatoonLeads <- data.frame(
  list(
    platoon = c("Data Wranglers", 
                "Data Miners", 
                "Data Vizards", 
                "Cadventurers"),
    name    = c("Kerry Halupka", 
                "Kim Doyle", 
                "Isabell Kiral-Kornek", 
                "Louise van der Werff")))
PlatoonLeads
##          platoon                 name
## 1 Data Wranglers        Kerry Halupka
## 2    Data Miners            Kim Doyle
## 3   Data Vizards Isabell Kiral-Kornek
## 4   Cadventurers Louise van der Werff

lists

lists

shoppingList <- list(
  breakfast = c("cereal", "milk", "orange juice", "banana"),
  lunch     = c("bread", "cheese", "tomato"),
  dinner    = c("frozen pizza", "chocolate mousse")
  )
shoppingList
## $breakfast
## [1] "cereal"       "milk"         "orange juice" "banana"      
## 
## $lunch
## [1] "bread"  "cheese" "tomato"
## 
## $dinner
## [1] "frozen pizza"     "chocolate mousse"

dictionaries

dictionaries

IMDBRatings = {"Game of Thrones": 9.4, 
    "Sherlock": 9.2, 
    "Firefly": 9.1, 
    "Friends": 8.9}
  
for movie, rating in IMDBRatings.items():
    print (movie,':',rating)

How to add flexibility to the conversation

If statements

How to add flexibility to the conversation

For loops

How to add flexibility to the conversation

Functions

Where to find help

Making mistakes is the best way to learn